<?php
/**
 * @package CRM
 * @subpackage HELPERS
 * @version 1.0

 */

/* returns a UTF-8 string lower*/
function strLower($string) {
    return mb_convert_case(strSpace($string), MB_CASE_LOWER, "UTF-8");
}

/* returns a UTF-8 string upper*/
function strUpper($string) {
    return mb_convert_case(strSpace($string), MB_CASE_UPPER, "UTF-8");
}

/* returns a UTF-8 string title*/
function strTitle($string) {
    return mb_convert_case(strSpace($string), MB_CASE_TITLE, "UTF-8");
}

/* clears multiple spaces   ; tabs, new lines and carriages are also replaced */
function strSpace($string) {
    $string = preg_replace('/\s+/', ' ', trim($string));
    return $string;
}

function copyPost(&$aRes, $aKey = null) {
    $CI = &get_instance();
    if (empty($aKey)) {
        $aKey = array_keys($_POST);
    }
    foreach ($aKey as $sKey) {
        if (isset($_POST[$sKey])) {
            $aRes[$sKey] = trim($CI->input->post($sKey));
        }
    }
}

function arrayToObject($array) {
    if (!is_array($array)) {
        return $array;
    }

    $object = new stdClass();
    if (is_array($array) && count($array) > 0) {
        foreach ($array as $name => $value) {
            $name = strtolower(trim($name));
            if (!empty($name)) {
                $object->$name = arrayToObject($value);
            }
        }
        return $object;
    }
    else {
        return FALSE;
    }
}

function e($aData, $mes = null) {
    log_message("error", $mes . print_r($aData, true));
}


/* End of file str_helper.php */
/* Location: ./system/application/helpers/str_helper.php */